<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>MYMSGRO</title>
	<link rel="stylesheet" type="text/css" href="css/main.css" />
	<link rel="stylesheet" type="text/css" href="css/meniu.css" />
	<link rel="stylesheet" type="text/css" href="css/style.css" />

</h:head>
<h:body>

	<ui:include src="header.xhtml" />

	<h:panelGroup layout="block" id="content">

		<ui:include src="leftMenu.xhtml" />

		<h:panelGroup layout="block" id="contenRight">

			<h:panelGroup layout="block" id="header" style="margin-top: 20px;">
				<ul>
					<li id="selected"><a>Book's Reviews</a></li>
				</ul>
			</h:panelGroup>

			<h:panelGroup layout="block" id="contentTab">
				<h:form id="bookForm">

					<h:commandButton style="width:50px; height:30px;"
						image="resources/img/back-button.png"
						action="#{bookTableData.backToBooks}" immediate="true"></h:commandButton>

					
					<br />


					<br />
					<b>Book Title: </b>
					<h:outputText value="#{bookTableData.currentBookBean.book.name}" />
					<br />
					<b>Author: </b>
					<h:outputText value="#{bookTableData.currentBookBean.book.author}" />
					<br />
					<br />
					<h:outputText value="There are no reviews for this book"
						styleClass="inputAreYouSure"
						rendered="#{bookTableData.currentBookBean.reviewsSize == 0}" />
					<br />
					<h:panelGroup rendered="#{bookTableData.deletionReview == true}"
						layout="block">
						<h:outputText value="Are you sure you want to delete?"
							styleClass="inputAreYouSure">
						</h:outputText>
						<h:commandButton value="Yes"
							action="#{bookTableData.deleteReview}" ></h:commandButton>
						<h:commandButton value="No"
							action="#{bookTableData.setDeletionReviewFalse}"
							></h:commandButton>
					</h:panelGroup>
					<p:dataTable id="reviewsDataDable"
						value="#{bookTableData.currentBookBean.reviews}" var="review"
						paginator="true" rows="5"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15"
						rendered="#{bookTableData.currentBookBean.reviewsSize > 0}">
						<p:column>
							<f:facet name="header">
								<h:outputText value="Author" />
							</f:facet>
							<h:outputText value="#{review.userFullName}" title="true"></h:outputText>
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Review" />
							</f:facet>
							<h:outputText value="#{review.text}" style="white-space: pre"></h:outputText>
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Delete" />
							</f:facet>
							<h:commandButton style="width: 30px;"
								image="resources/img/delete.png"
								actionListener="#{bookTableData.sureDeleteReview}"
								disabled="#{userDTO.id != review.userId}">
								<f:attribute name="currentReview" value="#{review}" />
							</h:commandButton>
						</p:column>
					</p:dataTable>

					<br />

					<h:outputText value="Write a review:" />

					<br />
					<h:inputTextarea id="inputReview"
						value="#{bookTableData.reviewText}" requiredMessage="true">
						<f:validateLength maximum="2000" />
					</h:inputTextarea>

					<br />

					<h:commandButton id="saveButton" value="Save Review"
						action="#{bookTableData.saveReview}" styleClass="buttonSurveyAnswer"/>

					<h:commandButton id="cancelButton" value="Cancel"
						action="#{bookTableData.cancelReview}" styleClass="buttonSurveyAnswer" />

				</h:form>
			</h:panelGroup>
		</h:panelGroup>
	</h:panelGroup>
</h:body>
</html>
